package org.huntaway.kindergarten.service.daily;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.huntaway.kindergarten.manager.DutyMng;
import org.huntaway.kindergarten.manager.TeacherGroupMng;
import org.huntaway.kindergarten.manager.TeacherMng;
import org.huntaway.kindergarten.po.Teacher;
import org.huntaway.kindergarten.service.KindProcessor;
import org.huntaway.kindergarten.util.EnumUse;
import org.huntaway.kindergarten.util.GlobalCon;

public class TeacherService extends KindProcessor<Teacher> {
	public TeacherService() {
		super();
		baseMng = (TeacherMng) sm.getMng(GlobalCon.TEACHER);
	}

	@Override
	public Teacher getObj() {
		return new Teacher();
	}

	public ActionForward addBegin(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionForward serBean = super
				.addBegin(mapping, form, request, response);
		request.setAttribute("tgLst", ((TeacherGroupMng) sm
				.getMng(GlobalCon.TEACHER_GROUP)).getTeacherGroup());
		request.setAttribute("dutyLst",
				((DutyMng) sm.getMng(GlobalCon.DUTY)).getDuty());
		return serBean;
	}

	public ActionForward addProcess(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionForward serBean = super.addProcess(mapping, form, request,
				response);
		request.setAttribute("resLst", dateManage
				.findbyhql("from TeacherGroup").list());
		item.setIsuse(EnumUse.NO.getValue());
		dateManage.save(item);
		return serBean;
	}
	public ActionForward editBegin(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionForward serBean = super
				.editBegin(mapping, form, request, response);
		request.setAttribute("tgLst", ((TeacherGroupMng) sm
				.getMng(GlobalCon.TEACHER_GROUP)).getTeacherGroup());
		request.setAttribute("dutyLst",
				((DutyMng) sm.getMng(GlobalCon.DUTY)).getDuty());
		return serBean;
	}
	public ActionForward query(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		item = (Teacher) setValue(request, getObj());
		TeacherMng itemMng = (TeacherMng) sm.getMng(GlobalCon.TEACHER);
		request.setAttribute("tgLst", ((TeacherGroupMng) sm
				.getMng(GlobalCon.TEACHER_GROUP)).getTeacherGroup());
		request.setAttribute("dutyLst", itemMng.query(item));
		return serBean;
	}
}
